<?php
namespace app\admin\controller;
use think\Controller;
use app\admin\model\CardModel;
use app\admin\model\CateModel;
use app\admin\model\EvaluateModel;
class Card extends Admin
{
	//加载帖子列表页面
    public function index()
    {
    	$cardList = (new CardModel())->cardList();
    	$this->assign('cardList',$cardList);
        $this->assign('title','FLY后台管理-帖子管理');
        return view('Card/index');
    }
    //加载分类页面
    public function cate()
    {
    	$cateList = (new CateModel())->cateList();
    	$this->assign('cateList',$cateList);
    	$this->assign('title','FLY后台管理-分类列表');
    	return view('Card/cate');
    }
    //加载添加分类页面
    public function cateAdd()
    {
    	$this->assign('title','FLY后台管理-添加分类');
    	return view('Card/cateAdd');
    }

    //添加分类操作
    public function cateAddDo()
    {
    	if (request()->isPost()) {
    		$res = (new CateModel())->add(input('post.'));
    		if($res['valid'])
    		{
    			$this->success($res['msg'],'Card/cate');
    		}else{
    			$this->error($res['msg']);exit;
    		}
    	}
    }
    //加载修改分类页面
    public function cateEdit()
    {
        if(request()->isGet()){
            $cateInfo = (new CateModel())->cateEdit(input('id'));
            $this->assign('cateInfo',$cateInfo);
            $this->assign('title','FLY后台管理-修改分类');
            return view('Card/cateEdit'); 
        }  
    }
    //执行修改分类操作
    public function cateEditDo()
    {
        if(request()->isPost()){
            $res = (new CateModel())->cateEditDo(input('post.'));
            if($res['valid'])
            {
                $this->success($res['msg'],'Card/cate');
            }else{
                //说明修改失败
                $this->error($res['msg']);exit;
            }
        }


    }
    //加载评论页面
    public function evaluate()
    {
		$EvaluateList = (new EvaluateModel())->EvaluateList();
		// dump($EvaluateList);
		$this->assign('EvaluateList',$EvaluateList);
	    $this->assign('title','FLY后台管理-评论管理');
	    return view('Card/evaluate');
    }
    //置顶是与否的转换
    public function is_first()
    {
        $is_first = input('is_first');
        $id = input('id');
        $is = ($is_first == 0 ? 1: 0);
        // dump($is);
        //执行转换
        db('card')->where('id', $id)->update(['is_first' => $is]);
        $this->success('更新成功','Card/index');
    }
    //显示是与否的转换
    public function is_show()
    {
        $is_show = input('is_show');
        $id = input('id');
        $is = ($is_show == 0 ? 1: 0);
        // dump($is);
        //执行转换
        db('card')->where('id', $id)->update(['is_show' => $is]);
        $this->success('更新成功','Card/index');
    }

}
